package com.heima.service.impl;

import com.heima.mapper.TaskMapper;
import com.heima.pojo.Task;
import com.heima.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;


@Service
@Slf4j
public class TaskServiceImpl implements TaskService {

    @Autowired
    private TaskMapper taskMapper;

    @Override
    @Transactional
    public List<Task> taskReportInfo(String start, String end) {
        List<Task> taskList = new ArrayList<>();

        Task taskRepairTrue = taskMapper.taskRepairTrue(start, end); //repair 为true的
        taskRepairTrue.setRepair(true);
        Integer total1 = taskRepairTrue.getCompletedTotal() + taskRepairTrue.getProgressTotal() + taskRepairTrue.getCancelTotal();
        taskRepairTrue.setTotal(total1);

        Task taskRepairFalse = taskMapper.taskRepairFalse(start, end); //repair 为false的
        taskRepairFalse.setRepair(false);
        Integer total2 = taskRepairFalse.getCompletedTotal() + taskRepairFalse.getProgressTotal() + taskRepairFalse.getCancelTotal();
        taskRepairFalse.setTotal(total2);

        taskList.add(taskRepairTrue);
        taskList.add(taskRepairFalse);
        return taskList;
    }



}
